package com.examples.calendar.viewer.item;

import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class CalendarMain {	
	public static void main(String[] args) {
		
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());

		CalendarControl calendarCtrl = new CalendarControl(shell, SWT.NONE);
		CalendarItem calendarItem;
		CalendarColumn column;
		
		Image image = new Image(display, "sort_icon.gif");
		
		for (int i = 1; i < 32; i++) {
			calendarItem = new CalendarItem(calendarCtrl, "" + i, SWT.NONE);
			calendarItem.setImage(image);
		}
		
		/**
		 * Adding SWT control paint listener from viewer's constructor.
		 * 
		 * */
		CalendarViewer viewer = new CalendarViewer(calendarCtrl);
		
		/*CalendarHolidayFilter holidayFilter = new CalendarHolidayFilter();
		viewer.addFilter(holidayFilter);*/
		
		/**
		 * TODO Listener not working, should be able to return selected item on Control
		 */
		viewer.addSelectionChangedListener(new ISelectionChangedListener() {			
			@Override
			public void selectionChanged(SelectionChangedEvent event) {
				CalendarViewer tb = (CalendarViewer) event.getSource();
				tb.getControl();
				
			}
		});
		
		for(Days d : Days.values()){
			column = new CalendarColumn(calendarCtrl, SWT.NONE);
			column.setText(d.toString());
		}
		
		calendarCtrl.setHeaderVisible(true);
		calendarCtrl.setLinesVisible(true);

		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}
}